nice_things/config/Config.sh
The Config class can be used to parse an INI-based config format and retrieve the values of properties from it.
Usage examples
package_conf=#{{{ new Config }}} ./nice_package.conf || exit
if Config_get_string "$package_conf" pkg_version '[]' version; then
log_debug "The package version is '${pkg_version}'"
else
log_debug "Config property 'version' not found"
fi
Config
Since 0.3.0 · Source
import "{ Config }" from nice_things/config/Config.sh
SynopsisConfig <&self> <file>
Configuration
–
Description
Constructor for the Config class. Parse the config from the file specified in the <file> parameter and initialize the object with the values of all properties in it.
Usually, this constructor function should be invoked with the new macro, which takes care of creating the <&self> reference to the newly created object.
Options
–
Operands
<out_var>: Output variable; the result will be written to this variable.<file>: A config file to parse.
Stdin
–
Stdout
–
Exit status
0: Successful completion.12: Invalid self reference<&self>(abort).20: Could not find file at<file>.
Abort
Aborts if self reference <&self> is invalid.
Usage examples
package_conf=#{{{ new Config }}} ./nice_package.conf
Config_destructor
Since 0.3.0 · Source
import "{ Config_destructor }" from nice_things/config/Config_destructor.sh
SynopsisConfig_destructor <&self>
Configuration
–
Description
Clear all data associated with the object.
Options
–
Operands<&self>: Self reference.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.12: Invalid self reference<&self>(abort).
Abort
Aborts if self reference <&self> is invalid.
Usage examples
Config_destructor "$package_conf"
Config_get_array
Since 0.3.0 · Source
import "{ Config_get_array }" from nice_things/config/Config_get_array.sh
SynopsisConfig_get_array <&self> <out_var> <section> <property>
Configuration
–
Description
Get value of a property of type Array. A reference to the Array will be assigned to <out_var>.
Options
–
Operands
<&self>: Self reference.<out_var>: Output variable; the result will be written to this variable.<section>: Name of the section, including the square brackets.<property>: Name of the property.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.1:<property>not found.11: Invalid or missing arguments (abort).12: Invalid self reference<&self>(abort).
Abort
- Aborts on invalid or missing arguments.
- Aborts if self reference
<&self>is invalid.
Usage examples
Config_get_array "$package_conf" pkg_authors '[]' author
Config_get_string
Since 0.3.0 · Source
import "{ Config_get_string }" from nice_things/config/Config_get_string.sh
SynopsisConfig_get_string <&self> <out_var> <section> <property>
Configuration
–
Description
Get value of a property of type string. The result will be assigned to <out_var>.
Options
–
Operands
<&self>: Self reference.<out_var>: Output variable; the result will be written to this variable.<section>: Name of the section, including the square brackets.<property>: Name of the property.
Stdin
–
Stdout
–
Stderrlog_error.
Exit status
0: Successful completion.1:<property>not found.11: Invalid or missing arguments (abort).12: Invalid self reference<&self>(abort).21: Invalid property value in config file. Expected string but found array.
Abort
- Aborts on invalid or missing arguments.
- Aborts if self reference
<&self>is invalid.
Usage examples
Config_get_string "$package_conf" pkg_version '[]' version